package com.myapp.NativeForRN;

import android.widget.Toast;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.modules.core.DeviceEventManagerModule;

public class BaseBridgeModule extends ReactContextBaseJavaModule {

    //定义上下文对象
    public static ReactContext myContext;

    public BaseBridgeModule(ReactApplicationContext reactContext) {
        super(reactContext);
        myContext = reactContext;


    }


    @Override
    public String getName() {
        return "BaseBridge";
    }

    @ReactMethod
    public void show(String msg) {
        Toast.makeText(getReactApplicationContext(), msg, Toast.LENGTH_LONG).show();
    }

    @ReactMethod
    public void testPromise(final String type, Promise promise) {
        if (type.equals('1')) {
            promise.resolve("a");
        } else {
            promise.reject("b");
        }
    }

    @ReactMethod
    public void abc() {
        myContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("Test_NativeEmitter", null);
    }


}